package games.ninJump.data
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.getTimer;
	
	import games.ninJump.NinJump;
	import games.ninJump.ui.actions.ActionTrans;
	
	import interfaces.IAction;
	
	public class GameState extends EventDispatcher implements IAction
	{
		public static const GAME_WIDTH:Number  = 320;
		public static const GAME_HEIGHT:Number = 480;
		public static const LEFT_SIDE:Number = 30;
		public static const RIGHT_SIDE:Number = 290;
		public static const ENEMY_NAMES:Array= ["knight","horse","gargoyle_frozen"];
		public static const ENEMY_TOWERS:Array= ["archer1","catapult1","drawbridge",];
		public static var ENEMIES:Vector.<ActionTrans>;
		private var m_speed:Number;
		private var m_start:Boolean;
		private var m_pause:Boolean;
		private var m_pauseTime:Number;
		private var m_score:Number;
		private var m_now:Number;
		private var m_temp:int;
		private var m_target:NinJump;
		
		public function GameState(nj:NinJump)
		{
			m_target = nj;
			init();
		}
		
		public function init():void
		{
			m_score = 0;
			ENEMIES = new Vector.<ActionTrans>();
			speed = 2;
		}
		
		public function get target():NinJump
		{
			return m_target;
		}
		
		public function set start(b:Boolean):void
		{
			m_start = b;
			if(b)
			{
				m_temp = 0;
				m_now = getTimer();
				m_pauseTime = 0;
				m_score = 0;
			}
		}
		
		public function get start():Boolean
		{
			return m_start;
		}
		
		public function set pause(b:Boolean):void
		{
			m_pause = b;
			if(b)
			{
				m_pauseTime = getTimer();
			}else
			{
				m_now += (getTimer() - m_pauseTime);
			}
		}
		
		public function get pause():Boolean
		{
			return m_pause;
		}
		
		public function update(e:Object = null):void
		{
			if(!start)return;
			if(pause)return; 
			m_temp = (getTimer() - m_now) * .01 * m_speed;
			
			dispatchEvent(new Event(Event.CHANGE));
		}
		
		public function set speed(n:Number):void
		{
			m_speed = n;
			m_now = getTimer();
			m_score += m_temp;
			dispatchEvent(new Event(Event.CHANGE));
		}
		
		public function get speed():Number
		{
			return m_speed;
		}
		
		
		
		public function get score():int
		{ 			
			return m_score + m_temp;
		}
		
	}
}